﻿using System;
using System.Collections.Specialized;
using System.Configuration.Provider;
using Data.UserDb;

namespace Acc.Lib.Providers
{
    public abstract class ActionProvider : ProviderBase
    {
        public Int32 ServId { get; set; }

        public String ServName { get; set; }

        public override void Initialize(string name, NameValueCollection config)
        {
            if (null == config)
            {
                throw (new ArgumentNullException("config"));
            }
            if (string.IsNullOrEmpty(name))
            {
                name = "";
            }

            ServId = Int32.Parse(config["servId"]);
            ServName = config["servName"];
            base.Initialize(name, config);
        }

        protected abstract bool Serv(Orders order, ShopRepository sr);

        public bool GenericServ(Orders order, ShopRepository sr)
        {
           CheckOrder(order);

            return Serv(order, sr);
        }

        protected void CheckOrder(Orders order)
        {
            if (order.SrvStatus > 0)
                throw new Exception(String.Format("该订单已经处理，不能重复处理，处理时间:{0}", order.PayTime));
        }
    }
}